import { createRouter, createWebHistory } from 'vue-router'
let puildPath = window.__MICRO_APP_ENVIRONMENT__?'/app':'/'
let path = window.__MICRO_APP_ENVIRONMENT__?window.__MICRO_APP_BASE_ROUTE__:''
const routes = [
    {
      path: window.__MICRO_APP_BASE_ROUTE__,
      name: 'home',
      component: () => import('@/views/Home.vue')
    },
    {
      path: `${path}/dashboard`,
      name: 'dashboard',
      component: () => import('@/views/Dashboard.vue')
    },
    {
      path: `${path}/about`,
      name: 'about',
      component: () => import('@/views/About.vue')
    },
    {
      path: `${path}/settings`,
      name: 'settings',
      component: () => import('@/views/Settings.vue')
    },
    {
      path: '/:pathMatch(.*)*',
      name: 'not-found',
      component: () => import('@/views/NotFound.vue')
    }
]
	// 监听路由变化并通知主应用
	// router.afterEach((to) => {
	//     if (window.microApp) {
	//       window.microApp.dispatch({ type: 'routechange', path: to.fullPath })
	//     }
	// })
const router = createRouter({
  history: createWebHistory(puildPath), // 使用 HTML5 历史模式
  routes, // `routes: routes` 的缩写
});
 
export default router;